/**
 * 通用js方法封装处理
 * Copyright (c) 2019 aidex
 */

export function replaceAll(text, stringToFind, stringToReplace) {
	if (stringToFind == stringToReplace) return this;
	var temp = text;
	var index = temp.indexOf(stringToFind);
	while (index != -1) {
		temp = temp.replace(stringToFind, stringToReplace);
		index = temp.indexOf(stringToFind);
	}
	return temp;
}

export function handleUrl(itemUrl) {
	let reg = /((https|http|ftp|file):\/\/)([A-Za-z0-9\-.]+)(:[0-9]+){0,1}/g;
	if (itemUrl) {
		itemUrl = this.replaceAll(itemUrl, itemUrl.match(reg), '')
		var url = this.vuex_config.baseUrl + itemUrl || '/static/aidex/images/default-image.png';
		url = this.replaceAll(url, '\\', '/');
		return url + '?t=' + new Date().getTime();
	}
	return '/static/aidex/images/default-image.png';
}
